package com.pocket.insight.base.sql;

import com.pocket.insight.base.utils.StringUtil;
import com.pocket.insight.entity.Dataset;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * 描述：
 *
 * @author shuize
 * @create 2024/12/8
 */
public class DatasetSchemaProvider extends BaseSchemaProvider {

    private Map<String, Dataset.Metric> metricMap;
    private Map<String, Dataset.Field>  labelMap = new LinkedHashMap();
    private Map<String, Dataset.Metric> metricLabelMap = new LinkedHashMap();


    public DatasetSchemaProvider(Map<String, Dataset.Field> schemaMap, Map<String, Dataset.Metric> metricMap) {
        this.schemaMap = schemaMap;
        if (this.schemaMap != null) {
            schemaMap.values().forEach(field -> {
                if (StringUtils.isNotBlank(field.getLabel())) {
                    this.labelMap.put(field.getLabel(), field);
                }
            });
        }
        this.metricMap = metricMap;
        if (this.metricMap != null) {
            metricMap.values().forEach(metric -> {
                if (StringUtils.isNotBlank(metric.getLabel())) {
                    this.metricLabelMap.put(metric.getLabel(), metric);
                }
            });
        }
    }

    @Override
    public Map<String, Dataset.Metric> fetchMetricMap() {
        return this.metricMap;
    }

    @Override
    public List<Dataset.Field> getFields() {
        return this.schemaMap == null ? new ArrayList() : new ArrayList(this.schemaMap.values());
    }

}
